package com.loyal.rx3;

import androidx.annotation.NonNull;

import com.loyal.client.RxConfig;
import com.loyal.client.server.BasicSubscriber;

import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;

public abstract class BaseRxSubscriber<T> extends BasicSubscriber<T, RetroManager> implements Observer<T> {
    private Disposable disposable;

    public BaseRxSubscriber() {
        super();
    }

    public BaseRxSubscriber(@NonNull RxConfig config) {
        super(config);
    }

    @NonNull
    @Override
    protected RetroManager manager() {
        return RetroManager.getInstance();
    }

    @Override
    public void onSubscribe(@NonNull Disposable disposable) {
        this.disposable = disposable;
        showDialog();
    }

    @Override
    public void dispose() {
        if (null != disposable && !disposable.isDisposed())
            disposable.dispose();
    }

    @Override
    public void onError(@NonNull Throwable e) {
        if (null != disposable && !disposable.isDisposed())
            super.onError(e);
    }
}
